<template>
  <!--  <h2>登记单管理</h2>-->
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm"  :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="姓名" prop="consultName">
        <el-input v-model="queryParams.consultName" placeholder="请输入姓名" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="单位" prop="nuit">
        <el-input v-model="queryParams.nuit" placeholder="请输入单位" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="证件号码" prop="consultNum">
        <el-input v-model="queryParams.consultNum" placeholder="请输入证件号码" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="内容用途" prop="useTo">
        <el-input v-model="queryParams.useTo" placeholder="请输入内容用途" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="登记时间" prop="dateRange">
          <el-date-picker v-model="dateRange" type="daterange" value-format="yyyy-MM-dd" format="yyyy-MM-dd" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" style="width: 240px">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="利用目的" prop="utilizeAim">
        <el-select v-model="queryParams.utilizeAim" placeholder="请选择" clearable label-width="68px" @keyup.enter.native="handleQuery">
          <el-option v-for="dict in dict.type.DJD_LYMD" :key="dict.value" :label="dict.label"
                     :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

<!--    <el-row :gutter="10" class="mb8" ref="refbut">-->
<!--      <el-col :span="1.5">-->
<!--        <el-button type="danger" plain icon="el-icon-delete"  @click="handeleDelete"  v-hasPermi="['archive:myCollect:remove']">移除</el-button>-->
<!--      </el-col>-->
<!--    </el-row>-->

    <el-table ref="table" v-loading="loading" :data="dataList" :height="tableHeight" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" type="index" :index="table_index" width="55" align="center" prop="id"/>
      <el-table-column label="姓名" prop="consultName" align="center" :show-overflow-tooltip="true" />
      <el-table-column label="单位" prop="nuit" align="center" :show-overflow-tooltip="true" />
      <el-table-column label="电话号码" prop="phone" align="center" :show-overflow-tooltip="true" />
      <el-table-column label="证件类型" prop="numType" align="center" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <span v-for="(i, idx) in dict.type.IDTYPE" :key="idx">
            {{ scope.row.numType == i.value ? i.label : '' }}
          </span>
        </template>
      </el-table-column>
      <el-table-column label="证件号码" prop="consultNum" align="center" :show-overflow-tooltip="true" />
      <el-table-column label="登记时间" prop="createTime" align="center" :show-overflow-tooltip="true" />
      <el-table-column label="利用目的" prop="utilizeAim" align="center" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <span v-for="(i, idx) in dict.type.DJD_LYMD" :key="idx">
            {{ scope.row.utilizeAim == i.value ? i.label : '' }}
          </span>
        </template>
      </el-table-column>
      <el-table-column label="内容用途" prop="useTo" align="center" :show-overflow-tooltip="true"/>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
  </div>
</template>

<script>
import estimateTableHeight from "@/mixins/estimateTableHeight";
import {getTableList} from "@/api/archive/liyong/registerManagement";

export default {
  name: "index",
  mixins: [estimateTableHeight], // 混入方法
  archive_Dicts: ['DJD_LYMD', 'BGQX', 'IDTYPE'],
  data() {
    return {
      loading: true,
      dataList: [],
      total: 0,
      // 显示搜索条件
      showSearch: true,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        consultName: undefined,
        consultNum: undefined,
        nuit: undefined,
        utilizeAim: undefined,
        useTo: undefined,
        params:{}
      },
      dateRange: [],
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      getTableList(this.queryParams).then(response=>{
        this.dataList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    table_index(index){
      return (this.queryParams.pageNum-1) * this.queryParams.pageSize + index + 1;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      if (this.dateRange != null) {
        if (this.dateRange.length != 0) {
          this.queryParams.params['beginCreateTime'] = this.dateRange[0].toString() + " 00:00:00";
          this.queryParams.params['endCreateTime'] = this.dateRange[1].toString() + " 23:59:59";
        }
      } else {
        this.queryParams.params['beginCreateTime'] = undefined
        this.queryParams.params['endCreateTime'] = undefined
      }
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.dateRange = []
      this.queryParams.params['beginCreateTime'] = undefined
      this.queryParams.params['endCreateTime'] = undefined
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    handeleDelete(row) {
      const id = row.id || this.ids
      if(id.length == 0) {
        this.$message({ message: '请选择至少一条数据进行移除', type: 'warning' });
      } else {
        this.$modal.confirm('是否确认删除选中所选数据项？').then(function () { }).then(() => {
          deleteMyCollection(id.toString()).then(res => {
            if (res.code == "200") {
              this.$modal.msgSuccess("删除成功");
              this.getList();
            }
          })
        }).catch(() => { });
      }
    }
  }
}
</script>

<style scoped>

</style>
